#include "point.h"

Point::Point()
{
    elements[3] = 1;
}

Point::Point(double x, double y, double z)
{
    elements[0] = x;
    elements[1] = y;
    elements[2] = z;
    elements[3] = 1;
}

Point::Point(const Point &p)
{
    this->copy(p);
    elements[3] = 1;
}

Point::~Point()
{
}

Point& Point::operator=(const Point &p)
{
    if( this != &p ) {
        this->copy(p);
    }

    return *this;
}

void Point::copy(const Point &p)
{
    (*this)(0) = p(0);
    (*this)(1) = p(1);
    (*this)(2) = p(2);
}

Point operator+(const Point &p, const Vector &v)
{
    Point c;
    for(int i = 0 ; i < 3 ; i++)
        c(i) = p(i) + v(i);

    return c;
}

Vector operator-(const Point &p1, const Point &p2)
{
    Vector c;

    for(int i = 0 ; i < 3 ; i++)
        c(i) = p1(i) - p2(i);

    return c;
}

double operator*(const Point &left, const Vector &right)
{
    return left(0)*right(0) + left(1)*right(1) + left(2)*right(2);
}

double operator*(const Vector &left, const Point &right)
{
    return right*left;
}
